import request from '@/utils/request';
import { TableListQueryParams, TableListItem,RoleModuleItem } from './data.d';

export async function queryList(params?: TableListQueryParams): Promise<any> {
  return request({
    url: '/admin-module/List',
    method: 'POST',
    data:params
  });
}

export async function createData(params: Omit<TableListItem, 'id'>): Promise<any> {
  return request({
    url: '/admin-module/add',
    method: 'POST',
    data: params,
  });
}

export async function updateData(params: Omit<TableListItem, 'id'>): Promise<any> {
  return request({
    url: `/admin-module/update`,
    method: 'POST',
    data: params,
  });
}

export async function removeData(id: number): Promise<any> {
  return request({
    url: '/admin-module/delete', 
    method: 'POST',
	data: {id:id},
  });
}

export async function detailData(id: number): Promise<any> {
  return request({
    url: '/admin-module/getone', 
    method: 'POST',
	data: {id:id},
  });
}
/**
 * 角色的权限数组
 */
export async function queryRoleData(id: number): Promise<any> {
  return request({
	  url: '/admin-role-module/listByRole',
	  method: 'POST',
	  data: {id:id},
  });
}
/**
 * 设定角色的按钮权限
 */
export async function ApiUpdateRoleModuleBtns(roleId:number,moduleId:number,btns:string): Promise<any> {
  return request({
	  url: '/admin-role-module/UpdateRoleModuleBtns',
	  method: 'POST',
	  data: {
		 roleId, moduleId,btns
	  },
  });
}
/**
 * 设定角色的权限数组
 */
export async function updataRoleData( params:RoleModuleItem[]): Promise<any> {
  return request({
	  url: '/admin-role-module/updataRolePermission',
	  method: 'POST',
	  data: params,
  });
}

export async function ListByModule( id:number): Promise<any> {
  return request({
	  url: '/admin-role-module/ListByModule',
	  method: 'POST',
	  data: {
		  Id:id
	  },
  });
}
export async function updataModulePermission( ModuleId:string,roles:[]): Promise<any> {
  return request({
	  url: '/admin-role-module/updataModulePermission',
	  method: 'POST',
	  data: {
		  ModuleId:ModuleId,
		  Roles:roles
	  },
  });
}
